import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/erjidaohang/LoginView.vue')
  },
  {
    path: '/register',
    name: 'register',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/erjidaohang/RegisterView.vue')
  },
  {
    path: '/axiostest',
    name: 'axiostest',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/element-ui/AxiosTestView.vue')
  },
  {
    path: '/uiye',
    name: 'uiye',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/element-ui/UiYeView.vue')
  },
  {
    path: '/hometest',
    name: 'hometest',
    redirect:'/hometest/testsi',//默认
    component: () => import(/* webpackChunkName: "about" */ '../views/erdao2/HomeTest.vue'),
    children:[
      {
        path: '/hometest/testsi',
        name: 'testsi',
        component: () => import(/* webpackChunkName: "about" */ '../views/erdao2/TestSi.vue')
      }
    ]

  },
  {
    path: '/',
    name: 'home',
    redirect:'/home/myone',//默认
    component: HomeView,
    children:[
      {
        path: '/home/myone',
        name: 'myone',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/erjidaohang/MyOne.vue')
      },
      {
        path: '/home/mytwo',
        name: 'mytwo',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/erjidaohang/MyTwo.vue')
      },
      {
        path: '/home/about',
        name: 'about',
        // redirect:'/home/about/gou3-20',//重定向
        component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue'),
         children:[ 
            {
              path: '/home/about/gou3-20',
              name: 'gou3-20',
              // route level code-splitting
              // this generates a separate chunk (about.[hash].js) for this route
              // which is lazy-loaded when the route is visited.
              component: () => import(/* webpackChunkName: "about" */ '../views/weekend3-20/GouView.vue')
            },
            {
              path: '/home/about/gou3-22',
              name: 'gou3-22',
              // route level code-splitting
              // this generates a separate chunk (about.[hash].js) for this route
              // which is lazy-loaded when the route is visited.
              component: () => import(/* webpackChunkName: "about" */ '../views/weekend3-20/GouView2.vue')
            },
         ]
      },
       {
        path: '/home/tielu',
        name: 'tielu',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/TieLu.vue')
      },
      {
        path: '/home/gouzi',
        name: 'gouzi',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/GouZiView.vue')
     },
      {
        path: '/home/lyb',
        name: 'lyb',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/LiuYanView.vue')
      },
      {
        path: '/home/flexye',
        name: 'flexye',
        component: () => import(/* webpackChunkName: "about" */ '../views/FlexYeView.vue')
      },
      {
        path: '/home/echarts1',
        name: 'echarts1',
        component: () => import(/* webpackChunkName: "about" */ '../views/echarts/Tab1View.vue'),
      },
      {
        path: '/home/echarts2',
        name: 'echarts2',
        component: () => import(/* webpackChunkName: "about" */ '../views/echarts/Tab2View.vue'),
      },
      {
        path: '/home/store',
        name: 'store',
        component: () => import(/* webpackChunkName: "about" */ '../views/vuex/VuexStore.vue'),
      },
      {
        path: '/home/lianxiang',
        name: 'lianxiang',
        component: () => import(/* webpackChunkName: "about" */ '../views/erjidaohang/LianXiangView.vue'),
      },
     
    ]
  },
  
 
  
 
  
]

const router = new VueRouter({
  routes
})

// // vue router.beforeEach（全局前置守卫） beforeEach的钩子函数，它是一个全局的before 钩子函数， （before each）意思是在 每次每一个路由改变的时候都得执行一遍。
// router.beforeEach((to,from,next)=>{
//   // 从哪来，到哪去
//     // console.log(to,from)
//     // 若会话存储中有数据
//  let islogin  = sessionStorage.getItem('erdao');
//     /* 会造成死循环,因为如果登录失败，返回到login页，也是一个路由，router.beforeEach（全局前置守卫）又会执行跳转login页面，造成死循环，所以要判断是否在login页面，若在则执行next(),而不是next('/login')*/
//     //  if(islogin !='' && islogin !=null){
//     //       // 从哪来，到哪去
//     //         console.log(to,from)
//     //    console.log('登录成功')
//     //         next() //下一步
//     //  }else{
//    //    console.log('登录失败')
//     //    next('/login')
//     //  }
//   if(to.name == 'login'){
//     next()
//   }else{
//     if(islogin !='' && islogin !=null){
//       // console.log('登录成功')
//         next() //下一步
//     }else{
//       // console.log('登录失败')
//          next('/login')
//     }
//   }
// })
export default router
